
<template>
    <theme-box title="版本添加">
        <form class="form-horizontal" @submit.prevent v-el:form>
            <div class="box-body">
                <form-input title="版本号" :required="true" name="verNo"></form-input>
                <form-select title="应用类型" :options="typeOptions" :required="true" name="type"></form-select>
                <form-select title="是否强制更新" :required="true" :options="forceOptions" name="isForce"></form-select>
                <form-select title="上传方式" :required="true" :options="flagOptions" name="flag"></form-select>
                <form-input title="服务器链接" :required="true" name="file"></form-input>
            </div>
            <!-- /.box-body -->
            <div class="box-footer">
                <v-button type="reset" @click="reset">重置</v-button>
                <v-button type="submit" theme="primary" class="pull-right">确认</v-button>
            </div>
            <!-- /.box-footer -->
        </form>
    </theme-box>

</template>

<script>
import 'plugins/jquery-validation';
import {dateTime} from 'ui/collections/general.js'

var serialize = require('form-serialize');

export default {
    data: () => ({
        typeOptions:[
            {key:"安卓",value:"1"},
            {key:"IOS",value:"2"},
        ],
        forceOptions:[
            {key:'是',value:'0'},
            {key:'否',value:'1'}
        ],
        flagOptions:[
            // {key:'本地上传',value:'0'},
            {key:'远程服务器上传',value:'1'}
        ],
    }),
    methods:{
        reset() {
            $("label.error").remove();
            this.$els.form.reset()
        }
    },
    ready() {
        dateTime()
        var self = this;
        $(this.$els.form).validate({
            submitHandler: async function() {
                var _data = serialize(this.currentForm, { hash: true, empty:true  });
                await self.$post({
                    url: "/api/"+ projectName_Url+ "/app/soft/add.html",
                    data: _data
                })
                let data = {
                    title: "操作成功",
                    content: "是否进入管理员列表查看?"
                }
                Midway.confirm(data).then(function () {
                    self.$route.router.go('/APP/version/list');
                })
                self.reset()
            },
            rules:{
                verNo:{
                    required:true,
                    version:true
                },
                file:{
                    required: true,
                    stringMaxLength: 200
                }
            },
            messages:{

            }
        });
    }
}
</script>
